<template>
  <teleport to="#modal">
    <div class="modal fade show d-block" v-if="isShow">
      <div class="modal-dialog">
        <div class="modal-content">
          <div class="modal-header">
            <h5 class="modal-title">{{ title }}</h5>
            <button
              type="button"
              class="btn-close"
              data-bs-dismiss="modal"
              aria-label="Close"
            ></button>
          </div>
          <div class="modal-body">
            <p><i class="bi bi-exclamation-octagon me-2"></i>{{ content }}</p>
          </div>
          <div class="modal-footer">
            <button
              type="button"
              class="btn btn-outline-primary"
              @click="handleClose"
            >
              取 消
            </button>
            <button
              type="button"
              class="btn btn-primary"
              @click="handleConfirm"
            >
              确 定
            </button>
          </div>
        </div>
      </div>
    </div>
    <div class="modal-backdrop fade show" v-if="isShow"></div>
  </teleport>
</template>
<script lang="ts">
import { defineComponent, ref } from 'vue'
import useCreateDom from '@/hooks/useCreateDom'
export default defineComponent({
  name: 'Modal',
  model: {},
  props: {
    title: {
      type: String,
      default: '提示'
    },
    content: {
      type: String,
      default: '是否确认删除？'
    },
    isShow: {
      type: Boolean,
      default: false
    }
  },
  emits: ['update:isShow', 'on-confirm', 'on-close'],
  setup(props, { emit }) {
    useCreateDom('modal')
    const handleConfirm = () => {
      emit('on-confirm')
    }
    const handleClose = () => {
      emit('update:isShow', false)
      emit('on-close')
    }
    return {
      handleClose,
      handleConfirm
    }
  }
})
</script>
